var px = {
	toggle : function(elements, event){
		var default_hide = {"grid": true };
		$.each(
			elements,
			function() {
				var el = $("#" + (this == 'accordon' ? 'accordion-block' : this) );
				if (default_hide[this]) {
					el.hide();
					$("[id='toggle-"+this+"']").addClass("hidden")
				}
				$("[id='toggle-"+this+"']")
					.bind(event, function(e) {
						if ($(this).hasClass('hidden')){
							$(this).removeClass('hidden').addClass('visible');
							el.slideDown();
						} else {
							$(this).removeClass('visible').addClass('hidden');
							el.slideUp();
						}
						e.preventDefault();
					});
			}
		);
	},
	sectionMenu : function(){
		$("#section-menu")
			.accordion({
				"header": "a.menuitem"
			})
			.bind("accordionchangestart", function(e, data) {
				data.newHeader.next().andSelf().addClass("current");
				data.oldHeader.next().andSelf().removeClass("current");
			})
			.find("a.menuitem:first").addClass("current")
			.next().addClass("current");
	},
	link : function(c, e, p){
		$(c)
			.bind(e, function(e) {
				if ($(p).hasClass('invisible')){
					$(p).removeClass('invisible').addClass('visible');
					$(p).show();
				} else {
					$(p).removeClass('visible').addClass('invisible');
					$(p).hide();
				}
				e.preventDefault();
			});
	},
	hide : function(){
		$("#box1").addClass("invisible");
		$("#box1").hide();
		$("#box2").addClass("invisible");
		$("#box2").hide();
		$("#box3").addClass("invisible");
		$("#box3").hide();
	}
};
var fx = {
	loadYoutube : function(){
		$.getJSON(
			"https://gdata.youtube.com/feeds/api/videos?alt=json",
			{
				q: 'app engine',
				'start-index': 1,
				'max-results': 3,
				v: 2
			},
			function(data) {
				// populate received data into <div> with id='liveContent'.
				// NOTE data.items
				$("#box2").append("<div class='block' id='videos'>");
				$.each(
					data.feed.entry,
					function(i,item){
						$("#box2").append("<a href='"+item.content.src+"'>"+"<img src='"+item.media$group.media$thumbnail[1].url+"'/></a>");
					});
				$("#box2").append("</div>");
			}
		);
	},
	signYahoo : function(){
		$.ajax({
			url: "https://login.yahoo.com/WSLogin/V1/get_auth_token",
			type: "GET",
			data: $(this).serialize(),
			success: function(res){              
				alert(res);
			},  
			error: function(xhr, ajaxOptions, thrownError){  
				alert("fail");  
			}  
		});
		return false;
	}
};
// Ready
$(function(){
	px.hide();
	px.link("#m1", "click", "#box1");
	$("#box1").draggable();
	var tElements = ["section-menu", "block1", "block2"];
	if ($("[id^='toggle']").length){
		px.toggle(tElements, "dblclick");
	}
	if ($("#section-menu").length){
		px.sectionMenu();
	}
	// fx.loadYoutube();
});